package com.bittech.chatroom.web.view;

import com.bittech.chatroom.web.config.listener.FreeMakerListener;
import freemarker.template.Configuration;
import freemarker.template.Template;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: yuisama
 * @Date: 2019-06-25 13:17
 * @Description:
 */
public class BaseViewServlet extends HttpServlet {
    protected Template getTemplate(String templateName, HttpServletRequest request, HttpServletResponse response) {
        ServletContext context = request.getServletContext();
        Configuration configuration = (Configuration) context.getAttribute(FreeMakerListener.TEMPLATE_KEY);
        try {
            return configuration.getTemplate(templateName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
